﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Solution.Utilities
{
     public class MoreFileHelper
    {
        private string path;
        private FileStream stream;

        public MoreFileHelper(string filePath)
        {
            path = filePath;
        }

        //public FileHelper(string filePath, FileAccess accessMode)
        //{
        //    path = filePath;
        //    stream = new FileStream(path, FileMode.OpenOrCreate, accessMode);
        //}

        private void OpenToRead()
        {
            stream = new FileStream(path, FileMode.Open, FileAccess.Read);
        }

        private void OpenToWrite()
        {
            stream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write);
        }

        private void OpenToAppend()
        {
            stream = new FileStream(path, FileMode.Append, FileAccess.Write);
        }

        public void AppendLine(string data)
        {
            this.OpenToAppend();
            StreamWriter sw = new StreamWriter(stream);

            sw.WriteLine(data);
            sw.Close();
        }

        public void WriteLine(string data)
        {
            this.OpenToWrite();
            StreamWriter sw = new StreamWriter(stream);

            sw.WriteLine(data);
            sw.Close();
        }

        public string ReadAll()
        {
            this.OpenToRead();
            StreamReader sr = new StreamReader(stream);

            string data = sr.ReadToEnd();
            sr.Close();

            return data;
        }
    }
}
